/*
	@file: log/source/logger_creator.cpp
	@author: Wolfhead
 */
#include "logger_creator/FileLoggerCreator.h"
#include "logger/FileLogger.h"
#include "Log.h"
#include "Builder.h"

namespace logger
{

LoggerPtr FileLoggerCreator::create_logger(
	boost::property_tree::ptree& setting)
{
	try
	{
		std::string filepath = setting.get<std::string>("path");
		boost::optional<std::string> interval = setting.get_optional<std::string>("interval");

		if (!interval)
		{
			interval = "00:00:00";
		}	

		boost::shared_ptr<FileLogger> logger_ptr(new FileLogger(filepath));

		if (0 != logger_ptr->set_interval(*interval))
		{
			CLOGS(kError) << "FileLoggerCreator::create_logger "
			                 "set_interval fail";
			return LoggerPtr();
		}

		return logger_ptr;
	}
	catch (boost::property_tree::ptree_error& ex)
	{
		CLOGS(kError) << "FileLoggerCreator::create_logger setting error:"
			          << ex.what();
		return LoggerPtr();
	}
}

}//namespace logger
